package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.HomePageRecycleBean;

import java.util.List;

/**
 * Created by admin on 2016/12/6.
 */
public class HomePageRecycleAdapter extends RecyclerView.Adapter<HomePageRecycleAdapter.MyViewHolder> {
    private Context context;
    private List<HomePageRecycleBean> recycleList;

    public HomePageRecycleAdapter(Context context, List<HomePageRecycleBean> recycleList) {
        this.context = context;
        this.recycleList = recycleList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.homepage_recycle_item, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.iv_img.setImageResource(Integer.parseInt(recycleList.get(position).getImg()));
        holder.tv_price.setText("¥ " + recycleList.get(position).getPrice());
        holder.tv_old_price.setText("¥ " + recycleList.get(position).getOld_price());
        holder.tv_old_price.getPaint().setAntiAlias(true);//抗锯齿
        holder.tv_old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
    }

    @Override
    public int getItemCount() {
        return recycleList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_img;
        TextView tv_price;
        TextView tv_old_price;

        public MyViewHolder(View view) {
            super(view);

            iv_img = (ImageView) view.findViewById(R.id.iv_img);
            tv_price = (TextView) view.findViewById(R.id.tv_price);
            tv_old_price = (TextView) view.findViewById(R.id.tv_old_price);
        }
    }
}
